//
//  WDRootViewController.m
//  qiJi
//
//  Created by 凤利史 on 2018/3/26.
//  Copyright © 2018年 sunrose. All rights reserved.
//

#import "WDRootViewController.h"
#import "WDRootFirstTableViewCell.h"
#import "WDRootFistSectionView.h"
#import "WDRootSecTableViewCell.h"

#import "WDRootSecSectionView.h"
#import "WDRootThreeTableViewCell.h"

#import "WDFenShiViewController.h"//我的粉丝
#import "WDGuanZhuViewController.h"//我的关注
#import "WDRootZhuangBeiViewController.h"//我的装备
#import "WDRootWDHDViewController.h"//我的活动
#import "WDRootSheZhiViewController.h"//设置
#import "WDFaBuViewController.h"//我的发布
#import "WDRootTiaoZhanViewController.h"//我的挑战
#import "WDGeRenXinXiViewController.h"//个人信息
#import "BieRenDongTaiViewController.h"
#import "QXZuTuanQiXingViewController.h"//我的组团
@interface WDRootViewController ()<UITableViewDelegate , UITableViewDataSource>
@property(nonatomic,strong) UITableView *huoDongTableView;

@end

@implementation WDRootViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = getColor(@"FAFAFA");
    [self creationView];
    [self regeditCell];
    
    // Do any additional setup after loading the view.
}
- (void)creationView{
    
    
    
    _huoDongTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 49)];
    _huoDongTableView.backgroundColor = getColor(@"FAFAFA");
    _huoDongTableView.delegate = self;
    _huoDongTableView.dataSource = self;
    _huoDongTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_huoDongTableView];
    
    UIView *threadView = [[UIView alloc]initWithFrame:CGRectMake(0, 1, DEF_SCREEN_WIDTH, 1)];
    threadView.backgroundColor = getColor(@"E6E6E6");
    [self.view addSubview:threadView];
    
}
- (void)regeditCell{
    
    //
    [self.huoDongTableView registerNib:[UINib nibWithNibName:@"WDRootFistSectionView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"WDRootFistSectionView"];
    
    [self.huoDongTableView registerNib:[UINib nibWithNibName:@"WDRootSecTableViewCell" bundle:nil] forHeaderFooterViewReuseIdentifier:@"WDRootSecTableViewCell"];
    
};
#pragma mark --- UITableViewDelegate ---
#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    
    if (section == 1) {
        return 55;
    }else if (section == 0) {
        
        return 0;
        
    }else{
        
        return 10;
    }
    
    
}


#pragma mark - ---------- Section的内容 ----------
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 1) {
        WDRootFistSectionView *sectionView = [self.huoDongTableView dequeueReusableHeaderFooterViewWithIdentifier:@"WDRootFistSectionView"];
        
        return sectionView;
    }else{
        
        WDRootSecSectionView *sectionView = [self.huoDongTableView dequeueReusableHeaderFooterViewWithIdentifier:@"WDRootSecSectionView"];
        
        return sectionView;
        
    }
    
    
    
    
    
    
}
#pragma mark - ---------- 每个Cell的高度 ----------
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        
       return 250;
    }else if (indexPath.section == 1){
        
        return 210*CHANGE_SIZE;
        
    }else{
        return 48*CHANGE_SIZE;
    }
    
}
#pragma mark - ---------- 每个Cell的点击事件 ----------
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 2) {
        if (indexPath.row == 1) {
            WDRootWDHDViewController *vc =  [[WDRootWDHDViewController alloc] init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
        }else if (indexPath.row == 0){
            WDRootTiaoZhanViewController *vc =  [[WDRootTiaoZhanViewController alloc] init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
        }else if (indexPath.row == 2){
            
            QXZuTuanQiXingViewController *vc = [[QXZuTuanQiXingViewController alloc] init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }else if (indexPath.section == 3){
        
        WDRootSheZhiViewController *vc = [[WDRootSheZhiViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (indexPath.section == 0){
        
        BieRenDongTaiViewController *vc = [[BieRenDongTaiViewController alloc] init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }
    
}

#pragma mark - ---------- Cell的数量 ----------

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 1;
    }else if (section == 2){
        return 3;
    }else{
        
        return 1;
    }
}
#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        [tableView registerClass:[WDRootFirstTableViewCell class] forCellReuseIdentifier:@"identifier"];
        WDRootFirstTableViewCell *cell = (WDRootFirstTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"identifier" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.fenShiButton addTarget:self action:@selector(fenShiClick) forControlEvents:UIControlEventTouchUpInside];
        [cell.guanZhuButton addTarget:self action:@selector(guanZhuClick) forControlEvents:UIControlEventTouchUpInside];
        
        [cell.zhuangBeiButton addTarget:self action:@selector(zhuangBeiClick) forControlEvents:UIControlEventTouchUpInside];
        [cell.faBuButton addTarget:self action:@selector(faBuClick) forControlEvents:UIControlEventTouchUpInside];
        [cell.headButton addTarget:self action:@selector(geRenXinXiClick) forControlEvents:UIControlEventTouchUpInside];
        
        
        return cell;
    }else if (indexPath.section == 1){
        
        [tableView registerClass:[WDRootSecTableViewCell class] forCellReuseIdentifier:@"identifier"];
        WDRootSecTableViewCell *cell = (WDRootSecTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"identifier" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
        
    }else if (indexPath.section == 2){
        
        [tableView registerClass:[WDRootThreeTableViewCell class] forCellReuseIdentifier:@"identifier"];
        WDRootThreeTableViewCell *cell = (WDRootThreeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"identifier" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSArray *titArr = @[@"我的挑战", @"我的活动",@"我的组团"];
        cell.titLab.text = titArr[indexPath.row];
        NSArray *pic = @[@"my_challenge_icon", @"my_activity_icon", @"my_cluster_icon"];
        cell.imgView.image = [UIImage imageNamed:pic[indexPath.row]];
        
        return cell;
    }else{
        
        [tableView registerClass:[WDRootThreeTableViewCell class] forCellReuseIdentifier:@"identifier"];
        WDRootThreeTableViewCell *cell = (WDRootThreeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"identifier" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.titLab.text = @"设置";
        
        cell.imgView.image = [UIImage imageNamed:@"my_set_icon"];
        
        return cell;
        
        
    }
    
    
}
//粉丝
- (void)fenShiClick{
    
    WDFenShiViewController *vc = [[WDFenShiViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
//关注
- (void)guanZhuClick{
    WDGuanZhuViewController *vc = [[WDGuanZhuViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
//装备
- (void)zhuangBeiClick{
    
    WDRootZhuangBeiViewController *vc = [[WDRootZhuangBeiViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
//我的发布
- (void)faBuClick{
    WDFaBuViewController *vc = [[WDFaBuViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
//个人信息
- (void)geRenXinXiClick{
    WDGeRenXinXiViewController *vc = [[WDGeRenXinXiViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
